/**
 * GeoSOA/Spatialytics/mapstyles/MapStyle.js
 *
 * Classes used to generate map styles for SOLAP layers
 *
 * Copyright (C) 2008-2009 GeoSOA Research Group, Universite Laval
 * See LICENSE file under this distribution for licensing information
 * 
 * @author Etienne Dube
 * @since 200807
 **/
 
dojo.provide("GeoSOA.Spatialytics.mapstyles.MapStyle");

dojo.require("GeoSOA.Spatialytics.mapstyles.contexts.IntervalsThematicContext");
dojo.require("GeoSOA.Spatialytics.Featurizer");

/**
 * Encapsulates the logic for styling of SOLAP layers
 * TODO: document better, add support for OpenLayers-style symbolizer rules 
 * 
 * @param {Object} options Options passed to the constructor
 * @constructor
 */
//GeoSOA.Spatialytics.mapstyles.MapStyle = function (options) {
dojo.declare("GeoSOA.Spatialytics.mapstyles.MapStyle", null, {

	constructor: function (options) {

		var that = this;
		var options = options || {};
	
		/**
		 * {Object} options.featurizer (optional)
		 * GeoSOA.Spatialytics.Featurizer object used to configure the mapping
		 * from the MDX query result (CellSet object) to a GeoJSON
		 * FeatureCollection.
		 * Since the application of a style for the SOLAP layer is dependent
		 * of the parameterization of the Featurize process (e.g. to specify
		 * which geometry member property must be used for plotting vector
		 * features), we associate a Featurizer object with a MapStyle.
		 * 
		 * Callers SHOULD specify a Featurizer according to the structure of the
		 * data cube and initial MDX query. If omitted, a default instance
		 * is created (according to the default values in Featurizer's ctor).
		 * 
		 * @public
		 */
		this.featurizer = options.featurizer || new GeoSOA.Spatialytics.Featurizer();
		
		/**
		 * {Object} options.thematicContext (optional) Context object to use
		 * (e.g. instantiated from IntervalsThematicContext)
		 * @public
		 */
		this.thematicContext = options.thematicContext ||
			new GeoSOA.Spatialytics.mapstyles.contexts.IntervalsThematicContext();
		
		/**
		 * {Object} options.thematicSymbolizer (optional) Symbolizer object to
		 * use for the style (see class OpenLayers.Style). Properties can be
		 * set to fixed values (e.g. "strokeColor: "#555555"") or can use a
		 * token specifying a function to call (member of the context object)
		 * to obtain the property value (e.g. "fillColor: "${getColor}").
		 * 
		 *  Default is a symbolizer calling a getColor function (see
		 *  IntervalsThematicContext) for the fill color.
		 */
		var _thematicSymbolizer = options.thematicSymbolizer ||
		{
			fillOpacity: 0.9,
			strokeColor: "#000000",
			strokeWidth: 0.5,
			fillColor: "${getColor}",
			label : "${getLabel}",
			fontSize: "10px",
			fontFamily: "Courier New, monospace",
			//fontWeight: "bold"
		};
		
		this._style = new OpenLayers.Style(_thematicSymbolizer,
				{context: that.thematicContext});
		
		this.styleMap = this.getDefaultStyleMap();
	},

	/**
	 * Get the OpenLayers Style object contained in this MapStyle
	 * 
	 * @return {OpenLayers.Style} OpenLayers Style object
	 * @public
	 */
	getStyle: function () {
		return this._style;
	},
	
	/**
	 * Get the OpenLayers StyleMap object contained in this MapStyle
	 * 
	 * @return {OpenLayers.StyleMap} OpenLayers StyleMap object
	 * @public
	 */
	getStyleMap: function () {
		return this.styleMap;
	},
	
	/**
	 * Get the featurizer contained in this MapStyle
	 * 
	 * @return {GeoSOA.Spatialytics.Featurizer} Featurizer object
	 * @public
	 */
	getFeaturizer: function () {
		return this.featurizer;
	},
	
	/**
	 * Get a default OpenLayers StyleMap object, with the Style object
	 * contained in this MapStyle as the default rendering intent.
	 * 
	 * @return {OpenLayers.StyleMap} OpenLayers StyleMap object
	 * @public
	 */
	getDefaultStyleMap: function () {
		// TODO: support rendering intents other than 'default'
		var style = this.getStyle();
		return new OpenLayers.StyleMap( {'default': style} );
	}

});
